import ast

from dotenv import load_dotenv
import os


class AppConfig:

    def __init__(self):
        load_dotenv()
        try:
            config = ast.literal_eval(os.getenv("JOURNEY_12306_DICT"))
        except Exception as e:
            config = {}
            print(e)

        self.database_url = config['database_url']

        self.dd_app_key = config['dd_app_key']
        self.dd_app_secret = config["dd_app_secret"]
        self.mobile = config["mobile"]

        self.imap_host = config["imap_host"]
        self.email = config["email"]
        self.password = config["password"]

        self.order_pattern = config["order_pattern"]
        self.ticket_pattern = config["ticket_pattern"]
        self.order_info_replace = config["order_info_replace"]
        self.email_pay_subject = config["email_pay_success_pattern"].split("|")
        self.email_refund_subject = config["email_refund_success_pattern"].split("|")

    def check(self) -> bool:
        if not self.database_url:
            print("database_url is empty!")
            return False
        if not self.dd_app_key:
            print("dd_app_key is empty!")
            return False
        if not self.dd_app_secret:
            print("dd_app_secret is empty!")
            return False
        if not self.mobile:
            print("mobile is empty!")
            return False
        if not self.imap_host:
            print("imap_host is empty!")
            return False
        if not self.email:
            print("email is empty!")
            return False
        if not self.password:
            print("password is empty!")
            return False
        if not self.order_pattern:
            print("order_pattern is empty!")
            return False
        if not self.ticket_pattern:
            print("ticket_pattern is empty!")
            return False
        if not self.order_info_replace:
            print("order_info_replace is empty!")
        if not self.email_pay_subject:
            print("email_pay_success_pattern is empty!")
        if not self.email_refund_subject:
            print("email_refund_success_pattern is empty!")
        return True


app_config = AppConfig()
